from django.urls import path,re_path,include

from apps.api.views import views,one2many,man2many,url_views,axiosDemo

app_name = 'apps.api'
namespace = 'api'

path_patterns = [
    # url 调度器 https://docs.djangoproject.com/zh-hans/3.2/topics/http/urls/
    path("urls/", url_views.url_demo_1, name="url_1"),
    # 相同路径会优先匹配转发
    path('urls/<int:year>/', url_views.year_archive),
    path('urls/<slug:year>/', url_views.year_archive_slug),
    path('urls/<str:year>/', url_views.year_archive_str),

    path('urls/<int:year>/<int:month>/', url_views.month_archive),
    path('urls/<int:year>/<int:month>/<slug:slug>/', url_views.article_detail),
    # 正则路径匹配
    re_path(r'^re_urls/(?P<year>[0-9]{4})/$', url_views.year_archive),
    re_path(r'^re_urls/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', url_views.month_archive),
    re_path(r'^re_urls/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<slug>[\w-]+)/$', url_views.article_detail),

    # 指定视图参数的默认值 http://xxx/urls7/page{num}}/
    path('urls7/', url_views.page),
    path('urls7/page<int:num>/', url_views.page),
]


urlpatterns = [
    # path('', views.IndexView.as_view(), name='index')
    path("login/", views.login, name="login"),
    path("index/", views.index, name="index"),

    # database
    path("addUser/", views.addUser, name="addUser"),  # database crud
    path("queryUser/", views.queryUser, name="queryUser"),  # database crud
    path("deleteUser/", views.deleteUser, name="deleteUser"),  # database crud
    path("editUser/", views.editUser, name="editUser"),  # database crud
    # 一对多
    path("addDepart/", one2many.addDepart, name="addDepart"),  # database one2many crud
    path("deleteDepart/", one2many.deleteDepart, name="deleteDepart"),  # database one2many crud
    path("addEmployee/", one2many.addEmployee, name="addEmployee"),  # database one2many crud
    path("addEmployeeByDepart/", one2many.addEmployeeByDepartement, name="addEmployeeByDepart"),  # database one2many crud
    path("deleteEmployee/", one2many.deleteEmployee, name="deleteEmployee"),  # database one2many crud
    path("queryEmployeeWithDepart/", one2many.queryEmployeeWithDepart, name="queryEmployeeWithDepart"),  # database one2many crud
    path("init/", one2many.init, name="init"),  # database one2many crud
    # 多对多
    path("many2many/", man2many.index, name="many2many"),

    # 包含其它的URLconfs url 调度器模块
    path('url/', include(path_patterns)),

    # axios
    path("axios", axiosDemo.hello, name="axios_hello"),

    # 测试
    # http://127.0.0.1:8000/api/testEnv
    path("testEnv", views.testEnv, name="testEnv"),


]
